var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/createField/utils.ts
var utils_exports = {};
__export(utils_exports, {
  enhanceFieldProps: () => enhanceFieldProps,
  enhanceRules: () => enhanceRules
});
module.exports = __toCommonJS(utils_exports);
var enhanceRules = (form, rules) => {
  return (rules || []).map((rule) => {
    if (typeof rule === "function")
      return rule;
    const { greaterThen, greaterThenEqual, lessThen, lessThenEqual, message } = rule;
    if (greaterThen) {
      return {
        validator: async (rule2, value) => {
          const targetValue = form.getFieldValue(greaterThen);
          const valueNum = value ? Number(value) : 0;
          const targetValueNum = targetValue ? Number(targetValue) : 0;
          if (value !== void 0 && targetValue !== void 0 && valueNum <= targetValueNum) {
            throw new Error(message || "最大值不能小于等于最小值");
          }
        }
      };
    } else if (greaterThenEqual) {
      return {
        validator: async (rule2, value) => {
          const targetValue = form.getFieldValue(greaterThenEqual);
          const valueNum = value ? Number(value) : 0;
          const targetValueNum = targetValue ? Number(targetValue) : 0;
          if (value !== void 0 && targetValue !== void 0 && valueNum < targetValueNum) {
            throw new Error(message || "最大值不能小于最小值");
          }
        }
      };
    } else if (lessThen) {
      return {
        validator: async (rule2, value) => {
          const targetValue = form.getFieldValue(lessThen);
          const valueNum = value ? Number(value) : 0;
          const targetValueNum = targetValue ? Number(targetValue) : 0;
          if (value !== void 0 && targetValue !== void 0 && valueNum >= targetValueNum) {
            throw new Error(message || "最小值不能大于等于最大值");
          }
        }
      };
    } else if (lessThenEqual) {
      return {
        validator: async (rule2, value) => {
          const targetValue = form.getFieldValue(lessThenEqual);
          const valueNum = value ? Number(value) : 0;
          const targetValueNum = targetValue ? Number(targetValue) : 0;
          if (value !== void 0 && targetValue !== void 0 && valueNum > targetValueNum) {
            throw new Error(message || "最小值不能大于最大值");
          }
        }
      };
    }
    return rule;
  });
};
var enhanceFieldProps = (props, rules, form) => {
  if (form && Array.isArray(rules)) {
    const fieldsToValidate = rules.filter((rule) => {
      return typeof rule !== "function" && (rule.greaterThen || rule.greaterThenEqual || rule.lessThen || rule.lessThenEqual);
    }).map(
      (rule) => rule.greaterThen || rule.greaterThenEqual || rule.lessThen || rule.lessThenEqual
    );
    if (fieldsToValidate.length) {
      const originOnChange = props.onChange;
      props.onChange = (...args) => {
        form.validateFields(fieldsToValidate);
        if (originOnChange)
          originOnChange(...args);
      };
    }
  }
  return props;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  enhanceFieldProps,
  enhanceRules
});
